package cst.a220tbc.framgmenttest_220tbc.Fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cst.a220tbc.framgmenttest_220tbc.R;
import cst.a220tbc.framgmenttest_220tbc.adapter.MyAdapter;
import cst.a220tbc.framgmenttest_220tbc.bean.ArticleBean;
import cst.a220tbc.framgmenttest_220tbc.iface.ArticleListener;
import cst.a220tbc.framgmenttest_220tbc.model.ArticleModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class WeixinFragment extends Fragment {
    private View view;
    private Context context;
    private RecyclerView recyclerView;
    private MyAdapter mAdapter;
    List<ArticleBean> list;
    private RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.recyclervView1);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //    list = getData();
        mAdapter = new MyAdapter(getActivity());
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);

    }
    ArticleListener articleListener=new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> l) {
            list= l;
            mAdapter.setList(list);
            //       mAdapter.notifyDataSetChanged();//通知数据改变
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context,"fail:"+msg,Toast.LENGTH_SHORT).show();
        }
    };


//    public WeixinFragment() {
//        // Required empty public constructor
//    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
//        TextView textView = new TextView(getActivity());
//        textView.setText(R.string.hello_blank_fragment);
        context=getActivity();
        view=inflater.inflate(R.layout.wfragment,container,false);
        initRecyclerView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"2ts2j910hv4m270hipde4a67d7",articleListener);
//        Toast.makeText(context,"这是微信主界面",Toast.LENGTH_SHORT).show();
        return view;
    }

    public void setLayoutManager(RecyclerView.LayoutManager layoutManager) {
        this.layoutManager = layoutManager;
    }


}
